package com.qkl.xiatang.app.service.impl;

import com.qkl.xiatang.app.dto.BusinessDTO;
import com.qkl.xiatang.app.dto.PageOutDTO;
import com.qkl.xiatang.app.dto.other.QueryCompanyInDTO;
import com.qkl.xiatang.app.entity.CompanyEntity;
import com.qkl.xiatang.app.mapper.CompanyMapper;
import com.qkl.xiatang.app.mapper.FeedMasterMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
@Slf4j
public class BreedService {

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private FeedMasterMapper feedMasterMapper;

    /**
     * 查询分公司列表
     * @param inDTO
     * @return
     */
    public BusinessDTO<PageOutDTO<CompanyEntity>> queryBranchCompanyList(QueryCompanyInDTO inDTO){
        inDTO.checkParam();
        Integer totalRow = companyMapper.queryBranchCompanyListTotal(inDTO);
        totalRow = null == totalRow? 0:totalRow;
        PageOutDTO<CompanyEntity> outDTO = new PageOutDTO();
        outDTO.settingPage(inDTO,totalRow);
        if(totalRow > 0){
            outDTO.setList(companyMapper.queryBranchCompanyList(inDTO));
        }
        if(ObjectUtils.isEmpty(outDTO.getList())){
            outDTO.setList(new ArrayList());
        }
        return BusinessDTO.sucessBusiness(outDTO,"查询分公司列表");
    }

}
